package com.hzhr.iot.collect.service.helper;

import com.hzhr.iot.collect.Global;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.sdk.model.iotDevice.IotDeviceModel;
import com.hzhr.iot.device.sdk.service.Device_IotDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class Device_IotDeviceServiceHelper {
    @Autowired
    Device_IotDeviceService device_iotDeviceService;
    @Autowired
    Global global;

    public IotDeviceModel getByIotPlatformDeviceId(String iotPlatformDeviceId) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_equal_iotPlatformDeviceId", iotPlatformDeviceId);
        query.put("_show", "one");
        query.put("_show_info", true);
        IotDeviceModel result = device_iotDeviceService.get(global.initGlobalHeader(), query).getModel();
        return result;
    }

    public IotDeviceModel getByCode(String code) throws ServiceException {
        Map<String, Object> query = new HashMap<>();
        query.put("_equal_code", code);
        query.put("_show", "one");
        query.put("_show_info", true);
        IotDeviceModel result = device_iotDeviceService.get(global.initGlobalHeader(), query).getModel();
        return result;
    }
}
